import React, { useEffect, useState } from 'react';
import StudentList from '../components/student/StudentList';
import StudentAdd from '../components/student/StudentAdd';
import StudentUpdate from '../components/student/StudentUpdate';
import { useComponentWillMount } from '../components/CustomHooks';
import axios from 'axios';
export default function(props){
    const [student,setStudent] = useState({});
    const [students,setStudents] = useState([]);
    const [pagination,setPagination] = useState({});
    const [updateVisible,setUpdateVisible] = useState(false);
    const [type,setType] = useState("");
    const [value,setValue] = useState("");

    const show = (page = 1,rows = 5,type,value) => {
  
        axios({
            method:"get",
            url:"/students",
            params:{
                page,rows,type,value
            }
        }).then(({data}) => {
            setStudents(data.rows);
            setPagination({
                current:data.curpage,
                pageSize:data.eachpage,
                total:data.total,
                
            });
            setType(type);
            setValue(value);
           
        })
    }
    const openUpdate = (student) => {
        setStudent(student);
        setUpdateVisible(true);
      
    }
    const closeUpdate = () => {
        setUpdateVisible(false);
       
    }
    useComponentWillMount(() => show());
    
    return (
        <div >
            <StudentAdd show={show}></StudentAdd>
            {/* <StudentsSearch show={this.show}></StudentsSearch>
             */}
             <StudentUpdate show={show} closeUpdate={closeUpdate} visible={updateVisible}  student={student}></StudentUpdate>
            <StudentList openUpdate={openUpdate} show={show} students={students} pagination={pagination}></StudentList>

        </div>
    )
}